using System;
using System.Collections;
using System.Collections.Generic;
using FrameWork;
using FrameWork.Inventory;
using Unity.VisualScripting;
using UnityEngine;

/// <summary>
/// 检测函数
/// 在这里执行玩家碰撞检测和射线检测
/// </summary>
public class PlayerDetection : MonoBehaviour
{
    /// <summary>
    /// 碰撞检测函数
    /// </summary>
    /// <param name="collision"></param>
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision != null)
        {
            // 获取金币
            if (collision.CompareTag("Coin"))
            {
                EventSystem.Instance.EventTrigger(EventName.EVENT_PLAYER_INFORMATION_UPDATE_COINS, 10);
                Destroy(collision.gameObject);
            }

            // 医院，回满血量
            if (collision.CompareTag("Hospital"))
            {
                EventSystem.Instance.EventTrigger(EventName.EVENT_PLAYER_INFORMATION_UPDATE_HEALTH, +100);
            }
            
            // NPC，获得物品
            INPC npc = collision.GetComponent<INPC>();
            if (npc != null)
            {
                if (PlayerManager.Instance.IsCanAddItemToInventory)
                {
                    // print("获得物品" + collision.gameObject.name);
                    // 添加物品并且销毁对象
                    EventSystem.Instance.EventTrigger(EventName.EVENT_INVENTORY_MODEL_ADDITEM, npc.GetItem(), 1);
                    Destroy(collision.gameObject);
                }
            }
        }
    }
}
